package com.lenovo.manufacture.module;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.beardedhen.androidbootstrap.BootstrapLabel;
import com.lenovo.manufacture.Adapter.recAdapter;
import com.lenovo.manufacture.R;
import com.lenovo.manufacture.net.BaseActivity;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class module5 extends BaseActivity {

    @BindView(R.id.m5_tv1)
    BootstrapLabel m5Tv1;
    @BindView(R.id.m5_tv2)
    BootstrapLabel m5Tv2;
    @BindView(R.id.m5_rv)
    RecyclerView m5Rv;
    List<Map<String, String>> maps;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_module5);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        m5Tv1.setTag(true);
        m5Tv2.setTag(true);
        async(data.getmaterial(), v -> {
            maps = v.getData();
            setList();
        });
    }

    private void setList() {
        List<String> list = new ArrayList<>();
        for (Map<String, String> map : maps) {
            list.add(map.get("materialName"));
            list.add(decimalFormat.format(Integer.valueOf(map.get("price"))));
            list.add(map.get("num"));
            list.add(map.get("supplyName"));
        }
        m5Rv.setLayoutManager(new GridLayoutManager(this, 4));
        m5Rv.setAdapter(new recAdapter(list));
    }

    @OnClick({R.id.m5_tv1, R.id.m5_tv2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.m5_tv1:
                sort(maps, "price", m5Tv1, "价格");
                break;
            case R.id.m5_tv2:
                sort(maps, "num", m5Tv2, "数量");
                break;
        }
        setList();
    }
}